<?php
//  ------------------------------------------------------------------------ //
//                XOOPS - PHP Content Management System                      //
//                    Copyright (c) 2000 xoops.org                           //
//                       <http://www.xoops.org/>                             //
//  ------------------------------------------------------------------------ //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  You may not change or alter any portion of this comment or credits       //
//  of supporting developers from this source code or any supporting         //
//  source code which is considered copyrighted (c) material of the          //
//  original comment or credit authors.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
// ------------------------------------------------------------------------- //
// Author: Dirk Herrmann (DHCST)                                             //
// Site: http://www.simple-xoops.de                                          //
// Project: The XOOPS Project                                                //
// ------------------------------------------------------------------------- //
if( ! defined( 'XOOPS_ROOT_PATH' ) ) die("XOOPS_ROOT_PATH not defined!");
if (!function_exists("info_freiblock_show")) {
function info_freiblock_show($options) {
     global $xoopsDB,$xoopsUser;  
	 $myts =& MyTextSanitizer::getInstance();	
	 $block = array();	
	 $result = $xoopsDB->query("SELECT * FROM ".$xoopsDB->prefix($options[0])." WHERE storyid=".$options[1]);
     $row = $xoopsDB->fetchArray($result);
	 $text = trim($row['text']);
	 if (intval($row['storyid']) != 0) {
	   $xoopsOption['template_main'] = $options[0].'_startblock.html';
       $html = (intval($row['nohtml']) == 1) ? 0 : 1; 
       $smiley = (intval($row['nosmiley']) == 1) ? 0 : 1;
       $breaks = (intval($row['nobreaks']) == 1) ? 0 : 1;
       $myts =& MyTextSanitizer::getInstance();
	   if (intval($row['link']) == 4) {
	     if (substr($row['address'],"/",0,1) || substr($row['address'],"\\",0,1)) $row['address']=substr($address,1);
		 $file = XOOPS_ROOT_PATH."/".$row['address'];
		 if (file_exists($file)) {
		   ob_start();
	       include($file);
	       $file = ob_get_contents();
           ob_end_clean();
	       $text=$file;
		 }
	   } elseif (intval($row['link']) == 5) {
	     $iframe=unserialize($row['frame']);
         if (!isset($iframe['width']) || $iframe['width']<1 || $iframe['width']>100) $iframe['width']=100;
         $text = "<div align='".$iframe['align']."'>";
         $text.= "<iframe WIDTH='".$iframe['width']."%' HEIGHT='".$iframe['height']."' NAME='".$row['title']."' SCROLLING='AUTO' FRAMEBORDER='".$iframe['border']."' SRC='".$row['address']."'></IFRAME>";
         $text.= "</div>";
		 $html = 1;
		 $breaks = 0;
	   }
     }
	 $text = str_replace('{X_XOOPSURL}', XOOPS_URL.'/', $text);
     if (is_object($xoopsUser)){
         $text = str_replace('{X_XOOPSUSER}', $xoopsUser->getVar('uname'), $text);
         $text = str_replace('{X_XOOPSUSERID}', $xoopsUser->getVar('uid'), $text);
     } else {
         $text = str_replace('{X_XOOPSUSER}',_GUESTS, $text);
         $text = str_replace('{X_XOOPSUSERID}', '0', $text);
     }
	 if ( trim($text) != '' ) {
	       $text = ereg_replace('<div style="page-break-after: always;"><span style="display: none;"> </span></div>','[pagebreak]',$text);
	       $infotext = explode("[pagebreak]", $text);
	       $info_pages = count($infotext);
	       if ($info_pages > 1) $text = $infotext[0];
	 }
     $text=$myts->displayTarea($text, $html, $smiley, $breaks);
	 $block['content'] = $text;
     return $block;
   }
}

if (!function_exists("info_freiblock_edit")) {
function info_freiblock_edit($options) {
  global $xoopsDB;
  $module_name = $options[0];
  $result=$xoopsDB->queryF("SELECT storyid,title FROM ".$xoopsDB->prefix($module_name)." WHERE link !=1 && link !=2 && link !=3 && link !=4");
  if ($result) {
	$form = "" . _INFO_BL_OPTION . "&nbsp;&nbsp;";
	$form .= "<input type='hidden' name='options[0]' value='".$module_name."'>";
	$form .= "<select name='options[1]' size='1'>";
	while ($row=$xoopsDB->fetcharray($result)) {
      $form .= "<option value='".$row['storyid']."'";
	  if ($options[1] == $row['storyid']) $form .= " selected";
	  $form .="> " . $row['title'] . " </option>";
	}
	$form .= "</select>";
    return $form;
  }
}
}
?>